﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SpreadsheetGear;
using SpreadsheetGear.Commands;

namespace WPFWorkbookDesigner.Model.SpreadSheet
{
    public class UndoableFill : CommandRange
    {
        internal UndoableFill(IRange range, FillDirection direction) : base(range)
        {
            Direction = direction;
        }
        private FillDirection Direction { get; }
        public override string DisplayText => "支持取消/重做命令的单元格复制指令";

        public override CommandUndoSupport UndoSupport => CommandUndoSupport.Full;

        protected override CommandRangeUndoFlags UndoFlags => CommandRangeUndoFlags.AutoFilters;
        protected override bool Execute()
        {
            try
            {
                switch (Direction)
                {
                    case FillDirection.Down:
                        Range.FillDown();
                        break;
                    case FillDirection.Left:
                        Range.FillLeft();
                        break;
                    case FillDirection.Right:
                        Range.FillRight();
                        break;
                    case FillDirection.Up:
                        Range.FillUp();
                        break;
                }
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected override bool Undo()
        {
            Range.Clear();
            return base.Undo();
        }

    }
}
